<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模块列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" th:href="@{/resource/css/bootstrap.min.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/font-awesome.min.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/animate.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/style.css}" />
    <link th:href="@{/resource/css/plugins/sweetalert/sweetalert.css}" rel="stylesheet">
    <link th:href="@{/resource/css/plugins/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/resource/css/plugins/toastr/toastr.min.css}" />

</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="row">
                        <div class="col-sm-10">  <h5>模块管理 &nbsp;/&nbsp;  <small>添加参数</small></h5></div>
                        <div class="col-sm-2">
                            <button type="button"  id="back_but" class="btn btn-white">返回</button>
                        </div>
                    </div>
                </div>
                <div class="ibox-content">
                <form class="form-horizontal m-t" id="commentForm" method="post">

                <div class="form-group">
                    <div class="col-md-7">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-9">
                                <p class="form-control-static" th:text="${modeModel.title}">这里是纯文字信息</p>
                                <input id="mid" type="hidden" class="form-control" name="mid" required="" aria-required="true" th:value="${modeModel.mid}"/>
                                <input id="type_tv" type="hidden" class="form-control" name="type_tv" required="" aria-required="true" th:value="${modeModel.type}"/>

                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题：</label>
                            <div class="col-sm-9">
                                <input id="title" type="text" class="form-control" name="title" required="true" th:value="${modeModel.title}" aria-required="true">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">类型：</label>
                            <div class="col-sm-9">
                                <select class="form-control" name="type" id="type" required="true"  th th:value="${modeModel.type}" onchange="setText()">
                                    <option value="0">每日上新</option>
                                    <option value="2">店铺推荐</option>
                                    <option value="3">聚划算</option>
                                    <option value="9">9块9</option>
                                    <option value="4">首页图块</option>
                                    <option value="5">单品商品</option>
                                    <option value="6">单个店铺</option>
                                    <option value="7">单独网页</option>
                                    <option value="8">单独专题</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label" id="tite_tv">参数：</label>
                            <div class="col-sm-9">
                                <input id="parameter" type="text" class="form-control" name="parameter"  th:value="${modeModel.parameter}"  required="true" aria-required="true" >

                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" id="model_submit" type="button">提交</button>
                            </div>
                        </div>

                        </div>
                    </div>

                  </form>

                <!-- End Example Events -->

            </div>
        </div>
    </div>


        </div>

    </div>


</div>




<div th:include="footer"></div>

<script type="text/javascript" th:src="@{/script/js/biz/product/favorite.js}"></script>


<script>
    $(function () {
        $("#type").val($("#type_tv").val());
    });

    
    function setText() {
        var type = $("#type").val();
        if(type==5){
            $("#tite_tv").html("商品ID");
        }else if(type==6){
            $("#tite_tv").html("店铺地址");
        }else if(type ==7){
            $("#tite_tv").html("网页地址");
        }else if(type ==8){
            $("#tite_tv").html("专题ID");
        }
    }


    $("#model_submit").click(function () {
        var title = $("#title").val();
        var type = $("#type").val();
        var mid = $("#mid").val();
        var parameter = $("#parameter").val();

        if (title == null || "" == title || type == null || type == ""|| parameter == null || parameter == "") {
            toastr.error("请补全信息");
             return
        }


        var mydata = '{"title":"'  + title + '","type":"'+type+'","parameter":"'+parameter+'","type":"'+type+'","mid":"'+mid+'"}';
        $.ajax({
            url: "/common/model/updateParameter",
            type: "post",
            data: mydata,
            contentType: "application/json",
            dataType:"json",
            success: function (data) {
                if(data["retType"] == "0") {
                    toastr.success("设置成功!");
                    setTimeout( "window.location.href='/common/model/doModelPage'",1000);//延时3秒

                } else {
                    toastr.error(data["retMsg"]);
                }
            }
        });
    });



</script>
</body>
</html>